package CutLoad.cookies
{
	import CutLoad.Base;
	import CutLoad.transitions.Easing;
	import CutLoad.transitions.ITransition;
	import CutLoad.transitions.TBase;
	import CutLoad.transitions.TransitionsData;
	import CutLoad.transitions.cloud.EasingFollowMe;
	
	import flash.geom.Point;
	
	public class LayoutTableTransition_EasingToHere extends TBase
	{
		//操作的目标
		private var easing:EasingFollowMe;
		//clone专用 
		private var clone_easingOffset:Number,clone_funEnterFrame:Function,clone_dxOver:Number,clone_dyOver:Number;
		public function LayoutTableTransition_EasingToHere(target:Base,easingOffset:Number=.2,funEnterFrame:Function=null,dxOver:Number=2,dyOver:Number=2)
		{
			clone_easingOffset=easingOffset;
			clone_funEnterFrame=funEnterFrame;
			clone_dxOver=dxOver;
			clone_dyOver=dyOver;
			if(target==null){
				//trace("LayoutTableTransition_EasingToHere.target==null")
				return;
			}
			if(funEnterFrame==null) funEnterFrame=function(me:LayoutTableTransition_EasingToHere):void{};
			this.funEnterFrame=funEnterFrame;
			easing=new EasingFollowMe(target,easingOffset,easing_funEnterFrame,dxOver,dyOver);
		}
		private function easing_funEnterFrame(me:EasingFollowMe):void{
			if(me.isComplete) me.pause();
			try{
				funEnterFrame(this);
			}catch(e:ArgumentError){
				funEnterFrame();
			}
			
		}
		/**
		 * 返回实际使用的缓动类。 
		 * @return 
		 * 
		 */		
		public function getEasing():EasingFollowMe{
			return easing;
		}
		/**
		 * 复制一个新的该对象，需要target参数 
		 * @param someData {target:Base}  target要操作的对象
		 * @return 
		 * 
		 */		
		override public function clone(someData:TransitionsData):ITransition{
			if(someData.target==null) throw new Error("需要target属性")
			return new LayoutTableTransition_EasingToHere(someData.target,clone_easingOffset,clone_funEnterFrame,clone_dxOver,clone_dyOver);
		}
		override public function start(data:TransitionsData=null):void{
			easing.follow(new Point(data.x,data.y));
			easing.start();
			//
		}
		override public function stop(someData:TransitionsData=null):void{
			KillMe();
		}
		/**
		 * 当前状态值 
		 * @return 0处于停止状态,1处于正在移动,2处于清除状态（调用过KillMe）
		 * 
		 */		
		override public function get state():Number{
			if(cs==2){
				return 2;	
			}
			if(easing.isComplete){
				return 0;
			}else{
				return 1;
			}
		}
		/**
		 * 关闭，并清除所有资源。 
		 * 
		 */		
		public function KillMe():void{
			cs=2;
			if(easing!=null){
				easing.killMe();
				easing=null;
			}
		}
	}
}